package com.kingviker.example.handler3;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MyCustomEncoder extends MessageToByteEncoder<MyCustomProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MyCustomProtocol msg, ByteBuf out) throws Exception {
        out.writeInt(MyCustomProtocol.HEAD_FLAG);
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}
